/*
 * @Author: 
 * @Date: 2022-01-27 10:30:21
 * @LastEditors: lqj
 * @LastEditTime: 2022-02-09 11:39:09
 * @Description: 请填写简介
 */
import React, { Component } from 'react';
import Search from './components/Search'
import List from './components/List'
// import {nanoid} from 'nanoid'
// import './style/index.css'
import axios from 'axios'

class GithubSearch extends Component {
  state = {
    searchList: [],
    isFirst: true,
    isLoad: false,
    isError: '',
    isEmpty: false
  }
  getDataList = (value) => {
    this.setState({ isFirst: false, isLoad: true })
    axios.get(`/api1/search/users?q=${value}`)
      .then(
        res => {
          // console.log(res.data.items)
          if (res.status !== 200) return
          this.setState({ searchList: res.data.items.map(it => it), isLoad: false })
        },
        err => {
          this.setState({isLoad: false, isError: err.message})
          console.log(err)
        }
      )
  }
  render() {
    return (
      <div className='container'>
        <Search getDataList={this.getDataList} updateAppState={this.updateAppState} />
        <List {...this.state} />
      </div>
    );
  }
}

export default GithubSearch;
